/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import core.Doctor;
import core.User;
import core.Users;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.JFrame;
import util.JCalendar;
import util.PopUpListener_WizytySwojlekarz_2;

/**
 *
 * @author Marcin
 */
public class RejestracjaReczna_wizyty extends javax.swing.JFrame {
    private int id_pacjenta;
    private int id_doktora;
    private JCalendar calendar;
    private DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    /**
     * Creates new form PatientForm
     */
    public RejestracjaReczna_wizyty(int id_pacjenta, int id_doktora) {
            initComponents();
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            this.id_pacjenta = id_pacjenta;
            this.id_doktora = id_doktora;
            
            User doktor = Users.getDoctorByHisID(id_doktora, this);
            User pacjent = Users.getDoctorByHisID(id_pacjenta, this);
            label_doktor.setText(doktor.getFirstName() + " " + doktor.getLastName());
            label_pacjent.setText(pacjent.getFirstName() + " " + pacjent.getLastName());
    
    
            Doctor d = new Doctor(Users.getDoctorByHisID(id_doktora, this), this);
            calendar = new JCalendar(new JCalendar.Hour(6, 0), new JCalendar.Hour(20, 30),15);
            calendar.update(d.getTerms(), JCalendar.CellType.AVAILABLE);
            calendar.getCalendar().addMouseListener(new PopUpListener_WizytySwojlekarz_2(calendar, new Doctor(Users.getDoctorByHisID(id_doktora, this), this), Users.getDoctorByHisID(id_pacjenta, this)));
            calendar.update(d.getHoliday(calendar.getFirstDayOfWeek(calendar.getDate()),
            calendar.getLastDayOfWeek(calendar.getDate())), JCalendar.CellType.HOLIDAY);
            calendar.update(d.getPacientsVisit(calendar.getFirstDayOfWeek(calendar.getDate()),
            calendar.getLastDayOfWeek(calendar.getDate())), JCalendar.CellType.VISIT);
            calendar.update(d.getPacientsTodayHomeVisit(), JCalendar.CellType.HOMEVISIT);

                        
       date.setText(df.format(calendar.getFirstDayOfWeek(calendar.getDate())) + " - "
        + df.format(calendar.getLastDayOfWeek(calendar.getDate())));
        scCalendar.setViewportView(calendar.getCalendar());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel2 = new javax.swing.JLabel();
        label_doktor = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        label_pacjent = new javax.swing.JLabel();
        scCalendar = new javax.swing.JScrollPane();
        prev = new javax.swing.JButton();
        next = new javax.swing.JButton();
        date = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Przychodnia");
        setMinimumSize(new java.awt.Dimension(300, 300));

        jLabel2.setText("Kalendarz wizyt doktorskich dla doktora:");

        jLabel4.setText("Rejestracja pacjenta:");

        scCalendar.setMaximumSize(new java.awt.Dimension(250, 360));
        scCalendar.setRequestFocusEnabled(false);

        prev.setText("Poprzedni tydzień");
        prev.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prevActionPerformed(evt);
            }
        });

        next.setText("Następny tydzień");
        next.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextActionPerformed(evt);
            }
        });

        date.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(scCalendar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(45, 45, 45)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label_pacjent)
                            .addComponent(label_doktor))
                        .addGap(0, 518, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(195, 195, 195)
                .addComponent(prev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(date)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(next)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(label_doktor))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(label_pacjent))
                .addGap(73, 73, 73)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(prev)
                    .addComponent(next)
                    .addComponent(date))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scCalendar, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void prevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevActionPerformed
                calendar.prevWeek();
        Doctor d = new Doctor(Users.getDoctorByHisID(id_doktora, this), this);
        calendar.clear();
            calendar.update(d.getTerms(), JCalendar.CellType.AVAILABLE);
           calendar.getCalendar().addMouseListener(new PopUpListener_WizytySwojlekarz_2(calendar, new Doctor(Users.getDoctorByHisID(id_doktora, this), this), Users.getDoctorByHisID(id_pacjenta, this)));
            calendar.update(d.getHoliday(calendar.getFirstDayOfWeek(calendar.getDate()),
            calendar.getLastDayOfWeek(calendar.getDate())), JCalendar.CellType.HOLIDAY);
            calendar.update(d.getPacientsVisit(calendar.getFirstDayOfWeek(calendar.getDate()),
            calendar.getLastDayOfWeek(calendar.getDate())), JCalendar.CellType.VISIT);
            calendar.update(d.getPacientsTodayHomeVisit(), JCalendar.CellType.HOMEVISIT);
        calendar.repaint();
        date.setText(df.format(calendar.getFirstDayOfWeek(calendar.getDate())) + " - "
            + df.format(calendar.getLastDayOfWeek(calendar.getDate()))); 
    }//GEN-LAST:event_prevActionPerformed

    private void nextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextActionPerformed
                      calendar.nextWeek();
        Doctor d = new Doctor(Users.getDoctorByHisID(id_doktora, this), this);
        calendar.clear();
            calendar.update(d.getTerms(), JCalendar.CellType.AVAILABLE);
           calendar.getCalendar().addMouseListener(new PopUpListener_WizytySwojlekarz_2(calendar, new Doctor(Users.getDoctorByHisID(id_doktora, this), this), Users.getDoctorByHisID(id_pacjenta, this)));
            calendar.update(d.getHoliday(calendar.getFirstDayOfWeek(calendar.getDate()),
            calendar.getLastDayOfWeek(calendar.getDate())), JCalendar.CellType.HOLIDAY);
            calendar.update(d.getPacientsVisit(calendar.getFirstDayOfWeek(calendar.getDate()),
            calendar.getLastDayOfWeek(calendar.getDate())), JCalendar.CellType.VISIT);
            calendar.update(d.getPacientsTodayHomeVisit(), JCalendar.CellType.HOMEVISIT);
        calendar.repaint();
        date.setText(df.format(calendar.getFirstDayOfWeek(calendar.getDate())) + " - "
            + df.format(calendar.getLastDayOfWeek(calendar.getDate()))); 
    }//GEN-LAST:event_nextActionPerformed


        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel date;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel label_doktor;
    private javax.swing.JLabel label_pacjent;
    private javax.swing.JButton next;
    private javax.swing.JButton prev;
    private javax.swing.JScrollPane scCalendar;
    // End of variables declaration//GEN-END:variables
}
